//
//  SJNetWorkTools.swift
//  SJWeiboSwift
//
//  Created by app;e on 15/10/3.
//  Copyright © 2015年 world. All rights reserved.
//

import UIKit
import AFNetworking

class SJNetWorkTools: AFHTTPSessionManager {
    ///工具类 单例
    class func sharedNetWorkTools()->SJNetWorkTools{
        return instance
    }
    
    private static let instance:SJNetWorkTools = {
        let url = NSURL(string: "https://api.weibo.com/")
        let tools = SJNetWorkTools(baseURL: url)
        tools.responseSerializer.acceptableContentTypes = NSSet(objects: "application/json", "text/json", "text/javascript","text/plain") as Set<NSObject>
        return tools
    }()
    
    // MARK: -发布微博
    func postStauts(text:String,finished:(error:NSError?)->()){
        
        //必须传人accessToken
        assert(sharedUserAccount?.access_token != nil, "accessToken 必须有值")
        
        let urlStr = "2/statuses/update.json"
        let params = ["access_token":sharedUserAccount!.access_token,"status":text]
        
        //发送内容
        POST(urlStr, parameters: params, success: { (_ , json) -> Void in
                finished(error: nil)
            }) { (_ , error ) -> Void in
                print(error)
                finished(error: error)
        }
    }
}
